import os.path
from PyQt5.QtGui import QPixmap, QPalette, QBrush, QIcon

Enum_Btn_Status = {
    "released"      : 0,
    "pressed"       : 1,
    "sticky"        : 2,
    "light_sticky"  : 3,
    # "releasing"   : -1
}

def Qt_set_bkground_img(qt_obj, path_pic):
    if not path_pic:
        return
    if not os.path.exists(path_pic):
        # LOG.error("Not found picture [%s]" % path_pic)
        raise FileExistsError

    # 仅用以设置背景色
    # qt_obj.setStyleSheet("background-color:blue;")

    # 用以设置背景图片
    # qt_obj.setObjectName("tmp")
    # qt_obj.setStyleSheet("#tmp{border-image:url(%s)}" % path_pic)

    palette	= QPalette()
    palette.setBrush(QPalette.Background, # Window
                     QBrush(QPixmap(path_pic)))

    qt_obj.setAutoFillBackground(True)
    qt_obj.setPalette(palette)

def Qt_set_icon(qt_obj, path_pic):
    """ 针对 QAbstractButton 等图元类型设置背景图 """
    if not path_pic:
        return
    if not os.path.exists(path_pic):
        raise FileExistsError

    # bitmap = QPixmap(path_pic)
    icon = QIcon(path_pic)  # QIcon(bitmap)

    qt_obj.setIconSize(qt_obj.size())
    qt_obj.setIcon(QIcon(path_pic))  # 限制：无法拉伸Icon图片，故只能让按钮适应图片

    # qt_obj.setFixedSize(bitmap.size())
    # qt_obj.setMask(bitmap.mask())
